﻿<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="CurrData.Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <title>Index </title>
    <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />

    <link href="/js/kd/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="/js/kd/styles/kendo.blueopal.min.css" rel="stylesheet" />
    <link href="/js/fa/css/font-awesome.min.css" rel="stylesheet" />
    <link href="/js/site.css?t=20221031" rel="stylesheet" />

    <script src="/js/kd/jquery.min.js"></script>
    <script src="/js/kd/kendo.web.min.js"></script>

    <script src="/js/kd/cultures/kendo.culture.zh-CN.min.js"></script>
    <script src="/js/kd/messages/kendo.messages.zh-CN.min.js"></script>
    <script src="/js/kd/jszip.min.js"></script>


    <script src="/js/kendo_stdefine.js"></script>
    <script src="/js/site50.js"></script>
    <script src="/js/xlsx.full.min.js?t=1"></script>


</head>
<body>
    <style>
        .lb_product2 {
            margin: 10px;
            line-height: 25px;
            border-bottom: 1px dashed #143c75;
            cursor: pointer;
            padding: 5px;
        }

            .lb_product2:hover:not(.k-state-selected) {
                background: #18477f80 !important;
            }

        .k-listview {
            border: none;
        }

        .divtitle {
            height: 30px;
            background: #18477f80 !important;
            margin-top: 5px;
        }
    </style>
    <script type="text/x-kendo-template" id="listtemplate">
        <div class="lb_product2">
            <div class="flexrow">
                <div style="width:50px;text-align:center;">#:RowNo#、</div>
                <div style="flex:1;">#:Name#</div>
            </div>
            <div class="flexrow">
                <div style="flex:1;">#:ShortName#</div>
            </div>
        </div>
    </script>

    <div id="divSplitter" data-role="splitter"
         data-panes="[
                { collapsible: false, resizable: false,  size: '245px' },
                { collapsible: false, resizable: false }
             ]"
         style="">
        <div id="left-pane" style="overflow:hidden;overflow-y:auto;">
            <div id="toolbarCenter" style="height:40px;line-height:40px;margin-bottom:2px;border-bottom: 1px solid #23549C;background:#14346a;font-family:'Microsoft YaHei'" class="flexrow">
                <div style="flex:1;margin-left:14px;font-size:14px">
                    协议定义
                </div>

                <div style="width:20px;color:#5999D4;">
                    <a id="btnAdd" style="cursor:pointer;" title="添加" onclick="Add()"><i class="fa fa-lg fa-plus"></i></a>
                </div>
                <div style="width:20px;color:#5999D4;">

                </div>
                <div style="width:20px;color:#5999D4;">
                    <a id="btnDelete" style="cursor:pointer;" title="删除" onclick="Delete()"><i class="fa fa-lg fa-trash"></i></a>
                </div>




            </div>
            <div id="listView" style="flex-wrap: wrap;overflow-x:hidden;overflow-y:auto ;height:calc( 100% - 45px)"></div>


        </div>

        <div id="center" style="overflow: hidden;overflow-y:auto; ">



        </div>


    </div>




    <script>
        var viewModel = new kendo.data.ObservableObject({
        });
        function Init() {
            kendo.bind($("#divSplitter"), viewModel);

            $("#listView").kendoListView({
                autoBind: false,
                template: kendo.template($("#listtemplate").html()),
                selectable: "single",
                dataBound: function () {
                    listView_dataBound();
                },
                change: function () {
                    var selectedItem = this.dataItem(this.select());
                    if (selectedItem) {
                        showDetail(selectedItem);
                    }

                }
            });

            List("");


        }
        var _currListViewId = "";
        function List(selid) {
            $("#center").html("");

            _currListViewId = selid;
            var url = "/api/ProtocolDefine/list"
            myAjaxList({
                url: url,
                success: function (r) {

                    var dsoptions = {
                        schema: {
                            model: {
                                id: "Id",
                                fields: { Id: { editable: false, nullable: true } }
                            }
                        },
                        data: r.Data,
                    };

                    var gridDataSource = new kendo.data.DataSource(dsoptions);
                    var listView = $("#listView").data("kendoListView");
                    listView.setDataSource(gridDataSource);
                    gridDataSource.read();
                }
            })
        }

        function listView_dataBound() {
            var listView = $("#listView").data("kendoListView");
            if (_currListViewId) {
                var item = listView.dataSource.get(_currListViewId);
                listView.select(".lb_product2[data-uid='" + item.uid + "'   ]");
            } else {
                listView.select(".lb_product2:first");
            }

        }


        var CurrData;
        function showDetail(m) {

            myAjax({
                url: "/api/ProtocolDefine/Detail",
                data: { Id: m.Id },
                success: function (r) {

                    CurrData = r.Data;
                    if (!CurrData.ZSBCS) {
                        CurrData.ZSBCS = []
                    }
                    if (!CurrData.SJZD) {
                        CurrData.SJZD = []
                    }

                    if (!CurrData.GDSJ) {
                        CurrData.GDSJ = []
                    }
                    if (!CurrData.XHSJ) {
                        CurrData.XHSJ = []
                    }
                    if (!CurrData.GDZL) {
                        CurrData.GDZL = []
                    }
                    showDetail2(m);
                }
            })
        }
        function showDetail2(m) {

            var s = `<div style="height:5px;"></div>
<div class="flexrow divtitle">
                                                                                                    <div style="width:20px;"></div>
                                                                                                    <div style="color: #40b4e4;width:20px;">
                                                                                                        <i class="fa fa-circle"></i>
                                                                                                    </div>
                                                                                                    <div style="width:100px;font-weight:bold;">基本信息  </div>
                                                                                                    <div style="flex:1;">
                                                                                                        <a id="btnEdit" style="cursor:pointer;" title="修改" onclick="Edit()"><i class="fa fa-lg fa-pencil"></i></a>
                                                                                                    </div>
                                                                                                    <div style="width:20px;">
                                                                                                          <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                                                    </div>
</div>
<div id="jbxx">
<div class="flexrow">
                                                                                                    <div class="tdLabel75">名称</div>
                                                                                                    <div class="tdValue">
                                                                                                        <input class="k-textbox" readonly="readonly" value="${m.Name}" />
                                                                                                    </div>
                                                                                                    <div style="width:20px;"></div>
</div>

<div class="flexrow">
                                                                                                    <div class="tdLabel75">简称</div>
                                                                                                    <div class="tdValue">
                                                                                                        <input class="k-textbox" readonly="readonly" value="${m.ShortName}" />
                                                                                                    </div>
                                                                                                    <div style="width:20px;"></div>
</div>

<div class="flexrow">
                                                                                                    <div class="tdLabel75">备注</div>
                                                                                                    <div class="tdValue">
                                                                                                        <textarea class="k-textbox" readonly="readonly" >${m.Memo}</textarea>
                                                                                                    </div>
                                                                                                    <div style="width:20px;"></div>
</div>
</div>


`;

            /*主设备参数*/
            s += `
<div class="flexrow divtitle">
                                                                                            <div style="width:20px;"></div>
                                                                                            <div style="color: #40b4e4;width:20px;">
                                                                                                <i class="fa fa-circle"></i>
                                                                                            </div>
                                                                                            <div style="width:100px;font-weight:bold;">主设备参数  </div>
                                                                                            <div style="flex:1;">
                                                                                                <a id="btnEdit" style="cursor:pointer;" title="修改" onclick="EditZSBCS()"><i class="fa fa-lg fa-pencil"></i></a>
                                                                                            </div>
                                                                                            <div style="width:20px;">
                                                                                               <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                                            </div>
</div>
<div>
`;
            for (var i = 0; i < CurrData.ZSBCS.length; i++) {
                s += `<div class="flexrow">
                                                                                            <div class="tdLabel75">参数${i + 1}</div>
                                                                                            <div class="tdValue">
                                                                                                <input class="k-textbox" readonly="readonly" value="${CurrData.ZSBCS[i].Name}" />
                                                                                            </div>
                                                                                            <div style="width:20px;"></div>
</div>`;
            }
            s += `
</div>`;
            /*主设备参数*/






            /*数据字典*/

            s += `<div class="flexrow divtitle">
                                                                                                    <div style="width:20px;"></div>
                                                                                                    <div style="color: #40b4e4;width:20px;">
                                                                                                        <i class="fa fa-circle"></i>
                                                                                                    </div>
                                                                                                    <div style="width:100px;font-weight:bold;">数据字典  </div>
                                                                                                    <div style="flex:1;">
                                                                                                        <a id="btnAdd" style="cursor:pointer;" title="添加" onclick="AddSJZD()"><i class="fa fa-lg fa-plus"></i></a>
                                                                                                    </div>
                                                                                                    <div style="width:20px;">
                                                                                                      <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                                                    </div>
</div>`;

            s += `
<div>`
            for (var i = 0; i < CurrData.SJZD.length; i++) {
                var data = GetSJZDMemo(CurrData.SJZD[i]);
                s += `<div class="flexrow" style="margin-top:5px;">


                                                                                                               <div  class="tdLabel75">${CurrData.SJZD[i].Name}
                                                                                                               </div>
                                                                                                               <div class="tdValue">
                                                                                                                    <textarea class="k-textbox" readonly  >${data}</textarea>
                                                                                                                </div>
                                                                                                                <div style="width:60px;">
                                                                                                                 <a id="btnAdd" style="cursor:pointer;margin-left:5px;" title="修改" onclick="EditSJZD(${i})"><i class="fa fa-lg fa-pencil"></i></a>
                                                                                                                 <a id="btnAdd" style="cursor:pointer;margin-left:5px;" title="删除" onclick="DeleteSJZD('${i}')"><i class="fa fa-lg fa-remove"></i></a>
                                                                                                                </div>

                                                                                                        </div>`;


            }

            s += `
</div>`
            /*数据字典*/


            /*请求主设备参数*/
            s += `<div class="flexrow divtitle">
                                                                    <div style="width:20px;"></div>
                                                                    <div style="color: #40b4e4;width:20px;">
                                                                        <i class="fa fa-circle"></i>
                                                                    </div>
                                                                    <div style="width:100px;font-weight:bold;">请求主设备参数</div>
                                                                    <div style="flex:1;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="添加" onclick="AddQQZSBCS()"><i class="fa fa-lg fa-plus"></i></a>
                                                                    </div>
                                                                    <div style="width:20px;">
                                                                       <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                    </div>
</div>
<div>
`;
            for (var i = 0; i < CurrData.QQZSBCS.length; i++) {
                s += `<div class="flexrow">
                                                                    <div class="tdLabel75">${CurrData.QQZSBCS[i].Name}


                                                                    </div>
                                                                    <div class="tdValue">
                                                                        <input class="k-textbox" readonly="readonly" value="${GetQQZSBCSMemo(CurrData.QQZSBCS[i])}" />
                                                                    </div>
                                                                    <div style="width:60px;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="修改" onclick="EditQQZSBCS(${i})"><i class="fa fa-lg fa-pencil"></i></a>
                                                                       <a id="btnAdd" style="cursor:pointer;margin-left:5px;" title="删除" onclick="DeleteQQZSBCS(${i})"><i class="fa fa-lg fa-remove"></i></a>
                                                                    </div>
                                              </div> `;
            }
            s += `
</div>`;


            /*请求主设备参数*/



            /*请求主设备数据*/
            s += `<div class="flexrow divtitle">
                                                                    <div style="width:20px;"></div>
                                                                    <div style="color: #40b4e4;width:20px;">
                                                                        <i class="fa fa-circle"></i>
                                                                    </div>
                                                                    <div style="width:100px;font-weight:bold;">请求主设备数据</div>
                                                                    <div style="flex:1;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="添加" onclick="AddQQGDSJ()"><i class="fa fa-lg fa-plus"></i></a>
                                                                    </div>
                                                                    <div style="width:20px;">
                                                                       <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                    </div>
</div>
<div>
`;
            for (var i = 0; i < CurrData.QQGDSJ.length; i++) {
                s += `<div class="flexrow">
                                                                    <div class="tdLabel75">${CurrData.QQGDSJ[i].Name}


                                                                    </div>
                                                                    <div class="tdValue">
                                                                        <input class="k-textbox" readonly="readonly" value="${GetQQGDSJMemo(CurrData.QQGDSJ[i])}" />
                                                                    </div>
                                                                    <div style="width:60px;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="修改" onclick="EditQQGDSJ(${i})"><i class="fa fa-lg fa-pencil"></i></a>
                                                                       <a id="btnAdd" style="cursor:pointer;margin-left:5px;" title="删除" onclick="DeleteQQGDSJ(${i})"><i class="fa fa-lg fa-remove"></i></a>
                                                                    </div>
                                              </div> `;
            }
            s += `
</div>`;


            /*请求主设备数据*/




            /*请求子设备数据*/
            s += `<div class="flexrow divtitle">
                                                                    <div style="width:20px;"></div>
                                                                    <div style="color: #40b4e4;width:20px;">
                                                                        <i class="fa fa-circle"></i>
                                                                    </div>
                                                                    <div style="width:100px;font-weight:bold;">请求子设备数据</div>
                                                                    <div style="flex:1;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="添加" onclick="AddQQXHSJ()"><i class="fa fa-lg fa-plus"></i></a>
                                                                    </div>
                                                                    <div style="width:20px;">
                                                                       <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                    </div>
</div>
<div>
`;
            for (var i = 0; i < CurrData.QQXHSJ.length; i++) {
                s += `<div class="flexrow">
                                                                    <div class="tdLabel75">${CurrData.QQXHSJ[i].Name}


                                                                    </div>
                                                                    <div class="tdValue">
                                                                        <input class="k-textbox" readonly="readonly" value="${GetQQXHSJMemo(CurrData.QQXHSJ[i])}" />
                                                                    </div>
                                                                    <div style="width:60px;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="修改" onclick="EditQQXHSJ(${i})"><i class="fa fa-lg fa-pencil"></i></a>
                                                                       <a id="btnAdd" style="cursor:pointer;margin-left:5px;" title="删除" onclick="DeleteQQXHSJ(${i})"><i class="fa fa-lg fa-remove"></i></a>
                                                                    </div>
                                              </div> `;
            }
            s += `
</div>`;


            /*请求子设备数据*/




            /*固定指令*/
            s += `<div class="flexrow divtitle">
                                                                    <div style="width:20px;"></div>
                                                                    <div style="color: #40b4e4;width:20px;">
                                                                        <i class="fa fa-circle"></i>
                                                                    </div>
                                                                    <div style="width:100px;font-weight:bold;">固定指令</div>
                                                                    <div style="flex:1;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="添加" onclick="AddGDZL()"><i class="fa fa-lg fa-plus"></i></a>
                                                                    </div>
                                                                    <div style="width:20px;">
                                                                       <i class="fa fa-chevron-up" onclick="updown_Click(this)"></i>
                                                                    </div>
</div>
<div>
`;
            for (var i = 0; i < CurrData.GDZL.length; i++) {
                s += `<div class="flexrow">
                                                                    <div class="tdLabel75">${CurrData.GDZL[i].Name}


                                                                    </div>
                                                                    <div class="tdValue">
                                                                        <input class="k-textbox" readonly="readonly" value="${GetGDZLMemo(CurrData.GDZL[i])}" />
                                                                    </div>
                                                                    <div style="width:60px;">
                                                                       <a id="btnAdd" style="cursor:pointer;" title="修改" onclick="EditGDZL(${i})"><i class="fa fa-lg fa-pencil"></i></a>
                                                                       <a id="btnAdd" style="cursor:pointer;margin-left:5px;" title="删除" onclick="DeleteGDZL(${i})"><i class="fa fa-lg fa-remove"></i></a>
                                                                    </div>
                                              </div> `;
            }
            s += `
</div>`;


            /*固定指令*/

            $("#center").html(s);
        }

        function updown_Click(sender) {
            var obj = $(sender);
            var p = obj.closest(".divtitle");

            if (obj.hasClass("fa-chevron-up")) {
                obj.removeClass("fa-chevron-up");
                obj.addClass("fa-chevron-down");
                var nextElement = p[0].nextElementSibling; // 获取p的同级下一个元素

                $(nextElement).toggle();
            } else {
                obj.removeClass("fa-chevron-down");
                obj.addClass("fa-chevron-up");
                var nextElement = p[0].nextElementSibling; // 获取p的同级下一个元素
                $(nextElement).toggle();
            }
        }

    </script>


    <!--基本信息-->
    <script>
        function Add() {

            var opt = myGetTop().GetFullWH();
            var w = 600;
            var h = 300;
            var url = "/ProtocolDefine/Add.html?t=" + Math.random();
            myWindowOpen({
                title: "添加协议"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = true;
                    win.setData({
                        Id: "0",
                        Name: "",
                        ShortName: "",
                        Memo: "",
                    });

                    win.onOk = function (m) {
                        AddSave(m);
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
        function AddSave(data) {
            myAjax({
                url: "/api/ProtocolDefine/Save",
                data: data,
                success: function (r) {
                    myWindowClose();
                    List(r.Data.Id)
                }
            })
        }
        function Edit() {

            var listView = $("#listView").data("kendoListView");
            var di = listView.dataItem(listView.select());
            if (!di) {
                return;
            }
            var m = di.toJSON();
            m = cloneData(m);


            var opt = myGetTop().GetFullWH();
            var w = 600;
            var h = 300;
            var url = "/ProtocolDefine/Add.html?t=" + Math.random();
            myWindowOpen({
                title: "修改协议"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = false;
                    win.setData(m);

                    win.onOk = function (m) {
                        CurrDataSave = cloneData(CurrData);
                        CurrDataSave.Name = m.Name;
                        CurrDataSave.ShortName = m.ShortName;
                        CurrDataSave.Memo = m.Memo;

                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
        function Delete() {
            var listView = $("#listView").data("kendoListView");
            var di = listView.dataItem(listView.select());
            if (!di) {
                return;
            }

            myConfirm({
                message: `确定要删除协议 ${di.Name} 吗？`,
                done: function () {
                    myAjax({
                        url: "/api/ProtocolDefine/Delete",
                        data: di.toJSON(),
                        success: function (r) {
                            List();
                        }
                    })
                }
            });

        }


        function SaveAll() {
            var data = CurrDataSave;
            if (data.toJSON) {
                data = data.toJSON();
            }
            myAjax({
                url: "/api/ProtocolDefine/Save",
                data: data,
                success: function (r) {
                    myWindowClose();
                    List(r.Data.Id);
                }
            })
        }

    </script>
    <!--基本信息-->
    <!--主设备参数-->
    <script>
        function EditZSBCS() {
            var opt = myGetTop().GetFullWH();
            var w = 600;
            var h = 400;
            var url = "/ProtocolDefine/AddZSBCS.html?t=" + Math.random();
            myWindowOpen({
                title: "主设备参数"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = true;
                    var data = CurrData.ZSBCS

                    win.setData(data);


                    win.onOk = function (m) {
                        CurrDataSave = cloneData(CurrData);
                        CurrDataSave.ZSBCS = m;
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
    </script>
    <!--主设备参数-->
    <!--数据字典-->
    <script>
        function AddSJZD() {

            var opt = myGetTop().GetFullWH();
            var w = 600;
            var h = 600;
            var url = "/ProtocolDefine/AddSJZD.html?t=" + Math.random();
            myWindowOpen({
                title: "添加数据字典"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = true;
                    var m = {
                        Id: "0",
                        Name: "",
                        Data: []
                    };
                    for (var i = 0; i < 10; i++) {
                        m.Data.push({
                            Name: "",
                            IMin: 0,
                            IMax: 0,
                            BJStatus: "",
                        })
                    }

                    win.setData(m);


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.SJZD.length; i++) {
                            if (CurrData.SJZD[i].Name == m.Name) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        m.Id = CurrDataSave.SJZD.length + 1;
                        CurrDataSave.SJZD.push(m);
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }

        function EditSJZD(index) {


            var m = CurrData.SJZD[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            m = cloneData(m);
            for (var i = 0; i < 10; i++) {
                m.Data.push({
                    Name: "",
                    IMin: 0,
                    IMax: 0,
                    BJStatus: "",
                })
            }

            var opt = myGetTop().GetFullWH();
            var w = 600;
            var h = 600;
            var url = "/ProtocolDefine/AddSJZD.html?t=" + Math.random();
            myWindowOpen({
                title: "修改数据字典"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = false;
                    win.setData(m);
                    win.onOk = function (m) {

                        for (var i = 0; i < CurrData.SJZD.length; i++) {
                            if (CurrData.SJZD[i].Name == m.Name
                                && CurrData.SJZD[i].Id != m.Id
                            ) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        for (var i = 0; i < CurrDataSave.SJZD.length; i++) {
                            if (CurrDataSave.SJZD[i].Id == m.Id) {
                                CurrDataSave.SJZD[i] = m;
                                break;
                            }
                        }
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
        function DeleteSJZD(index) {
            var m = CurrData.SJZD[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            myConfirm({
                message: `确定要数据字典 ${m.Name} 吗？`,
                done: function () {
                    CurrDataSave = cloneData(CurrData);
                    for (var i = 0; i < CurrDataSave.SJZD.length; i++) {
                        if (CurrDataSave.SJZD[i].Id == m.Id) {
                            CurrDataSave.SJZD.splice(i, 1);  // 删除匹配的元素
                            break;
                        }
                    }
                    for (var i = 0; i < CurrDataSave.SJZD.length; i++) {
                        CurrDataSave.SJZD[i].Id = i + 1;
                    }
                    SaveAll();
                }
            });

        }
        function GetSJZDMemo(m) {
            var s = "";
            for (var i = 0; i < m.Data.length; i++) {
                var item = m.Data[i]
                s += `${item.Name}:`;
                if (item.IMin != null && item.IMin != undefined
                    && item.IMax != null && item.IMax != undefined
                ) {
                    if (item.IMin == item.IMax) {
                        s += `${item.IMin};`;
                    } else {
                        s += `${item.IMin}~${item.IMax};`;
                    }
                } else if (item.IMin != null && item.IMin != undefined) {
                    s += `>=${item.IMin};`;
                } else {
                    s += `<=${item.IMax};`;
                }
            }
            return s;
        }



    </script>
    <!--数据字典-->
    <!--请求主设备参数-->
    <script>
        function AddQQZSBCS() {

            var opt = myGetTop().GetFullWH();
            var w = 600;
            var h = 600;
            var url = "/ProtocolDefine/AddQQZSBCS.html?t=" + Math.random();
            myWindowOpen({
                title: "添加请求主设备参数"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = true;
                    var m = {
                        Id: 0,
                        Gnm: 3,
                        StartAddress: 0,
                        ReqNum: 5,
                        Data: []
                    };

                    var data = [];
                    for (var i = 0; i < CurrData.ZSBCS.length; i++) {

                        data.push({

                            Name: CurrData.ZSBCS[i].Name,
                            Id: CurrData.ZSBCS[i].Id
                        })
                    }

                    win.setData({
                        m: m,
                        ZSBCSDs: data
                    });


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.QQZSBCS.length; i++) {
                            if (CurrData.QQZSBCS[i].Name == m.Name) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        m.Id = CurrDataSave.QQZSBCS.length + 1;
                        CurrDataSave.QQZSBCS.push(m);
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }

        function EditQQZSBCS(index) {


            var m = CurrData.QQZSBCS[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            m = cloneData(m);

            var opt = myGetTop().GetFullWH();
            var w = 600;
            var h = 600;
            var url = "/ProtocolDefine/AddQQZSBCS.html?t=" + Math.random();
            myWindowOpen({
                title: "修改请求主设备参数"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = false;
                    var data = [];
                    for (var i = 0; i < CurrData.ZSBCS.length; i++) {

                        data.push({

                            Name: CurrData.ZSBCS[i].Name,
                            Id: CurrData.ZSBCS[i].Id
                        })
                    }

                    win.setData({
                        m: m,
                        ZSBCSDs: data
                    });
                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.QQZSBCS.length; i++) {
                            if (CurrData.QQZSBCS[i].Name == m.Name &&
                                CurrData.QQZSBCS[i].Id != m.Id
                            ) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        for (var i = 0; i < CurrDataSave.QQZSBCS.length; i++) {
                            if (CurrDataSave.QQZSBCS[i].Id == m.Id) {
                                CurrDataSave.QQZSBCS[i] = m;
                            }
                        }
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
        function DeleteQQZSBCS(index) {
            var m = CurrData.QQZSBCS[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            myConfirm({
                message: `确定要删除请求主设备参数 ${m.Name} 吗？`,
                done: function () {
                    CurrDataSave = cloneData(CurrData);
                    for (var i = 0; i < CurrDataSave.QQZSBCS.length; i++) {
                        if (CurrDataSave.QQZSBCS[i].Id == m.Id) {
                            CurrDataSave.QQZSBCS.splice(i, 1);  // 删除匹配的元素
                            break;
                        }
                    }
                    for (var i = 0; i < CurrDataSave.QQZSBCS.length; i++) {
                        CurrDataSave.QQZSBCS[i].Id = i + 1;
                    }
                    SaveAll();
                }
            });

        }
        function GetQQZSBCSMemo(m) {
            var s = `功能码：${m.Gnm} 开始地址:${m.StartAddress} 数据数量:${m.ReqNum} 返回数据:`;
            for (var i = 0; i < m.Data.length; i++) {

                s += m.Data[i].Name + " ";
            }
            return s;
        }



    </script>
    <!--请求主设备参数-->
    <!--请求主设备数据-->
    <script>
        function AddQQGDSJ() {

            var opt = myGetTop().GetFullWH();
            var w = 1200;
            var h = 800;
            w = Math.min(w, opt.w - 100);
            h = Math.min(h, opt.h - 100);
            var url = "/ProtocolDefine/AddQQGDSJ.html?t=" + Math.random();
            myWindowOpen({
                title: "请求主设备数据"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = true;
                    var m = {
                        Id: 0,
                        Gnm: 3,
                        StartAddress: 0,
                        ReqNum: 5,
                        Data: [],
                        BitData: false,
                        LoopStatus: true,
                        LoopSencond: 0,
                    };

                    var data = [];
                    for (var i = 0; i < CurrData.SJZD.length; i++) {

                        data.push({

                            Name: CurrData.SJZD[i].Name,
                            Id: CurrData.SJZD[i].Id
                        })
                    }

                    win.setData({
                        m: m,
                        SJZD: data
                    });


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.QQGDSJ.length; i++) {
                            if (CurrData.QQGDSJ[i].Name == m.Name) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        m.Id = CurrDataSave.QQGDSJ.length + 1;
                        CurrDataSave.QQGDSJ.push(m);
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }

        function EditQQGDSJ(index) {
            var opt = myGetTop().GetFullWH();
            var w = 1200;
            var h = 800;
            w = Math.min(w, opt.w - 100);
            h = Math.min(h, opt.h - 100);

            var m = CurrData.QQGDSJ[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            m = cloneData(m);


            var url = "/ProtocolDefine/AddQQGDSJ.html?t=" + Math.random();
            myWindowOpen({
                title: "修改请求主设备数据"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = false;
                    var data = [];

                    for (var i = 0; i < CurrData.SJZD.length; i++) {

                        data.push({

                            Name: CurrData.SJZD[i].Name,
                            Id: CurrData.SJZD[i].Id
                        })
                    }

                    win.setData({
                        m: m,
                        SJZD: data
                    });


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.QQGDSJ.length; i++) {
                            if (CurrData.QQGDSJ[i].Name == m.Name &&
                                CurrData.QQGDSJ[i].Id != m.Id
                            ) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        for (var i = 0; i < CurrDataSave.QQGDSJ.length; i++) {
                            if (CurrDataSave.QQGDSJ[i].Id == m.Id) {
                                CurrDataSave.QQGDSJ[i] = m;
                            }
                        }
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
        function DeleteQQGDSJ(index) {
            var m = CurrData.QQGDSJ[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            myConfirm({
                message: `确定要删除请求主设备数据 ${m.Name} 吗？`,
                done: function () {
                    CurrDataSave = cloneData(CurrData);
                    for (var i = 0; i < CurrDataSave.QQGDSJ.length; i++) {
                        if (CurrDataSave.QQGDSJ[i].Id == m.Id) {
                            CurrDataSave.QQGDSJ.splice(i, 1);  // 删除匹配的元素

                            break;
                        }
                    }
                    for (var i = 0; i < CurrDataSave.QQGDSJ.length; i++) {
                        CurrDataSave.QQGDSJ[i].Id = i + 1;
                    }
                    SaveAll();
                }
            });

        }
        function GetQQGDSJMemo(m) {
            var s = `功能码：${m.Gnm} 开始地址:${m.StartAddress} `
            if (m.BitData) {
                s += ` 比特数据 `;
            }
            if (m.LoopStatus) {
                s += ` 循环间隔${m.LoopSencond}秒`;
            } else {
                s += ` 不循环 `;
            }
            s += `数据数量:${m.ReqNum} 返回数据:`;
            for (var i = 0; i < m.Data.length; i++) {

                s += m.Data[i].PropName + " ";
            }
            return s;
        }



    </script>
    <!--请求主设备数据-->
    <!--请求子设备数据-->
    <script>
        function AddQQXHSJ() {

            var opt = myGetTop().GetFullWH();
            var w = 1200;
            var h = 800;
            w = Math.min(w, opt.w - 100);
            h = Math.min(h, opt.h - 100);
            var url = "/ProtocolDefine/AddQQXHSJ.html?t=" + Math.random();
            myWindowOpen({
                title: "请求子设备数据"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = true;
                    var m = {
                        Id: 0,
                        Gnm: 3,
                        StartAddress: 0,
                        Data: [],
                        BitData: false,
                        LoopStatus: true,
                        LoopSencond: 0,
                        LoopBeginFml: "1",
                        LoopEndFml: "探测器数量",
                        LoopReqNum: 10,
                        ReqNum: 5,


                        DeviceCodeFml: "循环序号",

                    };

                    var data = [];
                    for (var i = 0; i < CurrData.SJZD.length; i++) {

                        data.push({

                            Name: CurrData.SJZD[i].Name,
                            Id: CurrData.SJZD[i].Id
                        })
                    }

                    win.setData({
                        m: m,
                        SJZD: data
                    });


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.QQXHSJ.length; i++) {
                            if (CurrData.QQXHSJ[i].Name == m.Name) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        m.Id = CurrDataSave.QQXHSJ.length + 1;
                        CurrDataSave.QQXHSJ.push(m);
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }

        function EditQQXHSJ(index) {
            var opt = myGetTop().GetFullWH();
            var w = 1200;
            var h = 800;
            w = Math.min(w, opt.w - 100);
            h = Math.min(h, opt.h - 100);

            var m = CurrData.QQXHSJ[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            m = cloneData(m);


            var url = "/ProtocolDefine/AddQQXHSJ.html?t=" + Math.random();
            myWindowOpen({
                title: "修改请求子设备数据"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = false;
                    var data = [];

                    for (var i = 0; i < CurrData.SJZD.length; i++) {

                        data.push({

                            Name: CurrData.SJZD[i].Name,
                            Id: CurrData.SJZD[i].Id
                        })
                    }

                    win.setData({
                        m: m,
                        SJZD: data
                    });


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.QQXHSJ.length; i++) {
                            if (CurrData.QQXHSJ[i].Name == m.Name &&
                                CurrData.QQXHSJ[i].Id != m.Id
                            ) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        for (var i = 0; i < CurrDataSave.QQXHSJ.length; i++) {
                            if (CurrDataSave.QQXHSJ[i].Id == m.Id) {
                                CurrDataSave.QQXHSJ[i] = m;
                            }
                        }
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
        function DeleteQQXHSJ(index) {
            var m = CurrData.QQXHSJ[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            myConfirm({
                message: `确定要删除请求子设备数据 ${m.Name} 吗？`,
                done: function () {
                    CurrDataSave = cloneData(CurrData);
                    for (var i = 0; i < CurrDataSave.QQXHSJ.length; i++) {
                        if (CurrDataSave.QQXHSJ[i].Id == m.Id) {
                            CurrDataSave.QQXHSJ.splice(i, 1);  // 删除匹配的元素
                            break;
                        }
                    }
                    for (var i = 0; i < CurrDataSave.QQXHSJ.length; i++) {
                        CurrDataSave.QQXHSJ[i].Id = i + 1;
                    }
                    SaveAll();
                }
            });

        }
        function GetQQXHSJMemo(m) {
            var s = `功能码：${m.Gnm} 开始地址:${m.StartAddress} `
            if (m.BitData) {
                s += ` 比特数据 `;
            }
            if (m.LoopStatus) {
                s += ` 循环间隔${m.LoopSencond}秒`;
            } else {
                s += ` 不循环 `;
            }
            s += `数据数量:${m.ReqNum} 返回数据:`;
            for (var i = 0; i < m.Data.length; i++) {

                s += m.Data[i].PropName + " ";
            }
            return s;
        }



    </script>
    <!--请求子设备数据-->


    <!--固定指令-->
    <script>
        function AddGDZL() {

            var opt = myGetTop().GetFullWH();
            var w = 1200;
            var h = 800;
            w = Math.min(w, opt.w - 100);
            h = Math.min(h, opt.h - 100);
            var url = "/ProtocolDefine/AddGDZL.html?t=" + Math.random();
            myWindowOpen({
                title: "添加固定指令"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = true;
                    var m = {
                        Id: 0,
                        Gnm: 3,
                        
                        Data: [],
                        
                        ReqNum: 6,

                         
                    };

                    
                    win.setData({
                        m: m 
                    });


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.GDZL.length; i++) {
                            if (CurrData.GDZL[i].Name == m.Name) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        m.Id = CurrDataSave.GDZL.length + 1;
                        CurrDataSave.GDZL.push(m);
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }

        function EditGDZL(index) {
            var opt = myGetTop().GetFullWH();
            var w = 1200;
            var h = 800;
            w = Math.min(w, opt.w - 100);
            h = Math.min(h, opt.h - 100);

            var m = CurrData.GDZL[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            m = cloneData(m);


            var url = "/ProtocolDefine/AddGDZL.html?t=" + Math.random();
            myWindowOpen({
                title: "修改固定指令"
                , url: url
                , width: w
                , height: h
                , isMaxH: false
                , onload: function (win) {
                    win.IsAdd = false;
                    var data = [];

                   

                    win.setData({
                        m: m,
                       
                    });


                    win.onOk = function (m) {
                        for (var i = 0; i < CurrData.GDZL.length; i++) {
                            if (CurrData.GDZL[i].Name == m.Name &&
                                CurrData.GDZL[i].Id != m.Id
                            ) {
                                myAlert("名称重复");
                                return;
                            }
                        }
                        CurrDataSave = cloneData(CurrData);
                        for (var i = 0; i < CurrDataSave.GDZL.length; i++) {
                            if (CurrDataSave.GDZL[i].Id == m.Id) {
                                CurrDataSave.GDZL[i] = m;
                            }
                        }
                        SaveAll();
                    }
                    myFocus(win);
                }
                , onclosed: function (win) {
                }
                , success: function (m) {
                }
            });
        }
        function DeleteGDZL(index) {
            var m = CurrData.GDZL[index];
            if (m.toJSON) {
                m = m.toJSON();
            }

            myConfirm({
                message: `确定要删除固定指令 ${m.Name} 吗？`,
                done: function () {
                    CurrDataSave = cloneData(CurrData);
                    for (var i = 0; i < CurrDataSave.GDZL.length; i++) {
                        if (CurrDataSave.GDZL[i].Id == m.Id) {
                            CurrDataSave.GDZL.splice(i, 1);  // 删除匹配的元素
                            break;
                        }
                    }
                    for (var i = 0; i < CurrDataSave.GDZL.length; i++) {
                        CurrDataSave.GDZL[i].Id = i + 1;
                    }
                    SaveAll();
                }
            });

        }
        function GetGDZLMemo(m) {
            var s = `功能码：${m.Gnm} `
            
            s += `数据数量:${m.ReqNum} 数据:`;
            for (var i = 0; i < m.Data.length; i++) {

                s += m.Data[i].ByteFml + " ";
            }
            return s;
        }



    </script>
    <!--固定指令-->
    <script>
        var SizeInfo;
        $(function () {

            kendo.culture("zh-CN");


            if (window.Init) {
                Init();
            }
        });
        function After50(d) {
            if (d) {
                setTimeout(function () { d(); }, 50);
            }
        }
    </script>
</body>
</html>
